﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;

namespace BusinessLogicLayer
{
    public class BangCapBLL
    {
        QuanLyChamCongDataContext DB = new QuanLyChamCongDataContext();

        public List<BANGCAP> LayTatCa()
        {
            return DB.BANGCAPs.ToList();
        }

        public void ThemBC(BANGCAP bangcap)
        {
            DB.BANGCAPs.InsertOnSubmit(bangcap);
            DB.SubmitChanges();
        }

        public string KiemTraTonTai(int maBC, string tenBC)
        {
            if (DB.BANGCAPs.Any(a => a.MaBangCap == maBC))
                return "Mã Bằng Cấp";
            if (DB.BANGCAPs.Any(b => b.TenBangCap == tenBC))
                return "Tên Bằng Cấp";
            else
                return null;
        }
        public bool KiemTraTenBC(int maBC, string tenBC)
        {
            if (DB.BANGCAPs.Any(a => a.TenBangCap == tenBC && a.MaBangCap != maBC))
                return true;
            else
                return false;
        }

        public BANGCAP LayBangCap(int mabc)
        {
            BANGCAP bc = DB.BANGCAPs.Single(a => a.MaBangCap == mabc);
            return bc;
        }

        public string LayTenBangCap(int mabc)
        {
            BANGCAP bc = DB.BANGCAPs.Single(a => a.MaBangCap == mabc);
            return bc.TenBangCap.ToString();
        }

        public void XoaBC(int mabc)
        {
            BANGCAP bc = LayBangCap(mabc);
            DB.BANGCAPs.DeleteOnSubmit(bc);
            DB.SubmitChanges();
        }

        public void SuaBC(BANGCAP bcn)
        {
            BANGCAP bco = DB.BANGCAPs.Single(a => a.MaBangCap == bcn.MaBangCap);
            bco.TenBangCap = bcn.TenBangCap;
            bco.MoTa = bcn.MoTa;
            DB.SubmitChanges();
        }
    }
}
